Tools for translating PS2 EU PAL version of Final fantasy X
(SCES_504.90)

Usage export:
-------------
(0.edit ffx*.tbs files, see below)
1. copy original FFX.iso to folder "iso" (iso\ffx.iso)
   (or edit workdir\!setParam.bat, iffxiso = input iso, offxiso = output iso)
   (version must be european english PAL - SCES_504.90)
2. iso_ffx.sfv
   or checkIsoHeader.bat
   (tool are only for european english PAL version - SCES_504.90)
3. extractFromISO.bat
4. result in folder "extracted"

Usage import:
-------------
1. after previous "export/import"
   or copy FFX.iso to folder "iso" (iso\ffx.iso)
2. copy translated data to folder "import"
   (translated data from folder "extracted")
3. importToISO.bat
4. result in "iso\ffx.iso" (changed)
5. after import reextract test, see bellow
   (reextract test is basic verification that everything is imported correctly)
   (important before final import or before testing)
6. after import test in game

Reextract test:
---------------
1. use clean ffxBats (not previously used for extract/import)
2. copy modified FFX.iso to folder "iso" (iso\ffx.iso)
   (iso used for import)
3. reextractFromISO.bat
    - prints errors, different files and "done" message
      (errors on extract or errors on compare duplicate extracted files)
   (extracted\td_* are folders with duplicates - those are compared against others)
4. compare folder "import" with data used for import with reextracted data in folder "extracted"
   (compare folder by content, for example with totalcommander)
    - folders with texts must be exactly same
    - folders with graphics can differ, must check manually if changed correctly
      (colour palette can differ in extracted/modified graphic files (alpha channel)
       (palette is not imported, but graphic editors can change it on save))
5. if found difference or printed error, need check it properly


Others bats:
------------
workdir\extractGraphicVariantsP.bat
 - more graphics variants, different file extensions, for example:  mixed in alfa channel extension "_ta", "_taM"
   (different colors variants because of same or similar colors with different transparency,
    on variants "_ta", "_taM" can be seen if colors are transparent, looking more like graphic in game)
 - extracted to folders "extracted\variantsGraphic" and "extracted\variantsGWorld_ta"
 - 32bit graphic import not supported, only 4/8bit graphic supported
   (32bit graphic used only for preview or for searching of graphic artifacts)
   (for import (4/8bit) need rename to original extracted name and copy to specific folder)


------------------------------------------------------------

Notes/TODO:
-----------
{VAR07:XX}
 - "Position X" in dialog window?
{CHOICE:51}
 - player select number?
.tbs files
 - same .tbs files are used for export and import
 - .tbs file should be changed before export
   (if value in .tbs changed after export, and present in exported texts,
    must also change it in exported texts, or import may write bad value)
   (for example: after change "\x02={u02}" to "\x02={unknown02}"
    need export texts again or replace "{u02}" in exported texts)
dlgmain
 - empty lines at dialog start are required (empty name of person)
   (if "inappropriate", dialog may not show)
dbattle
 - some texts are duplicates and are not exported. During import they are copied from others.
   (see workdir\importDbattle.bat, search "duplicit")
import
 - import is faster if fewer files are imported
 - is recommended to not import unchanged files
   (compression may differ from original and result files may be bigger)
text/graphic in "field" files (EV files)
 - field files with numbers : 0348 0513 0547 0739 0830 1023 1025 1029 1031 1070
   have text and graphic, must import both at once
   (if not imported at once, unimported part will be in original language)
   (some graphics are duplicate, thus some "field" files using graphic with different "field" number)
size limitation
 - All texts have limited space available. Tools should print error if there is not enough space.
   In that case texts size must be decreased or specially processed (only for .mt files, see below).
decreasing size of files
 - only for '.mt' files
 - must manually write filenames to importDother.bat  (for loop with ffxmt -i -x -t)
duplicate files
 - if printed error on file with unknown number, probably it is error on duplicate files
 - graphic/text - see import BAT where are duplicates created
duplicated battle files
 - edit workdir\wiso\eBt.bat and workdir\importDbattle.bat
 - because of duplicates, error can be printed for files which are not imported
   (search name in .bat mentioned above)
graphic
 - imports only 4/8bit BMP files, palette is not imported
   ("winXP mspaint" can be used to process those files,
    e.g. paste to it graphic from other editors)
 - graphic extraction can have more parameters (-ta/-n/-na)
   (some can be more useful than others for proper edit/import, but need proper testing
    some are required to use (-ta) to not get merged colors with same RGB values)
 - with current setting palette is not imported, only bitmap data
   (it is possible change colors in palette but index value of pixel must be kept)
   (for example is possible change RGB color of background in palette,
    but is required to keep same color index in bitmap)
 - ffxmap support for "gworld" palette import
   (with current setting it will cancel transparency except for first color in palette,
    turned on if imported from "import/gworld_p")
 - extracted palette is modified (original has transparency and 256 colors)
   to have background colors converted to magenta/green
   (black colors with alpha (0,0,0, X) to shades of magenta/green (based on alpha value))
 - 0225, 0226, 0229, 0230 supports mask
   (m02??.bmp in same folder, if in mask is pixel with index 0 then matching pixel from 02??.bmp is not imported)
 - 0229 support more masks, names must match (for each 0229*.bmp matching m0229*.bmp)
 - for extracting is possible more settings (parameters -t4, -ta for ffxgnop),
   but for import there must be 8/4bit graphic (32bit can be inserted to 8bit graphic file in winXP mspaint)


------------------------------------------------------------

More notes:
-----------

Working only on European FFX
Verify with iso_ffx.sfv or with checkIsoHeader.bat 
(Working only on original FFX, on modified can print error!)


First "extract" will extract original files which are then used for imports.
They are extracted only once at first use of "extract".
In case of troubles, delete whole folder and start again with clean files.
(First "extract" extracts files which are not extracted on next "extract")


For export and import is used same ISO file.
Extract after importing modified files can cause extract imported files
or mixed files (some modified, some original).


------------------------------------------------------------

TODO:
mt2 (0174, 0177, 0180) better import, currently not increasing size (can cause troubles?)
mt2 using fixed sizes while working with data from english version
mt2 using special mark {END} (others are not using it)
(because of using different tool, and because of opcodes ending with "zero",
 and there was error when removing {END})

------------------------------------------------------------

Workarounds:
(deprecated, solved by replacing ffxtool and compressing to size of original file)
 - ffxtool not write "zero end", solving with ffxlba parameter '-ac'
 - ffxtool sometimes bad compression (LZSS) at end of file
   solved by giving RLE of compressed data at end of such known files
 - some EV files required fixed size, solved by ffxev parameter '-k'
   (not known reason of damaged file in memory of PS2 emulator - examined memory snapshot
    if files had specific or original size there was no damage to data
    (original size created by adding zeros at file end))
